package com.zzyang.mybatis.jdbc.factory;

import org.springframework.context.ApplicationContext;

/**
 * 基于spring的扩展工厂
 *
 * @author yisuan
 * @date 2021/4/10 13:13
 */
public class SpringExtensionFactory implements ExtensionFactory {

    public static final SpringExtensionFactory INSTANCE = new SpringExtensionFactory();

    private static ApplicationContext applicationContext;

    public static void setApplicationContext(ApplicationContext applicationContext) {
        if (SpringExtensionFactory.applicationContext == null) {
            SpringExtensionFactory.applicationContext = applicationContext;
        }
    }

    @Override
    public <T> T getInstance(String name, Class<T> clazz) {
        return applicationContext.getBean(name, clazz);
    }

}
